/****** Object:  UserDefinedFunction [dbo].[fn_Decrypt]    Script Date: 06/09/2015 17:05:24 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_Decrypt]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fn_Decrypt]
GO

/****** Object:  UserDefinedFunction [dbo].[fn_Decrypt]    Script Date: 06/09/2015 17:05:24 ******/
CREATE FUNCTION [dbo].[fn_Decrypt] 
(
	@cipherText VARCHAR(50)
)
RETURNS VARCHAR(50)
AS
BEGIN
DECLARE
	@encryptedBinary VARBINARY(255),
	@decrypted VARCHAR(50)

SET @encryptedBinary = CAST(N'' AS XML).value('xs:base64Binary(sql:variable("@cipherText"))', 'varbinary(255)')
SET @decrypted = CONVERT(VARCHAR(50), DecryptByPassPhrase([Global].dbo.fn_OpenSesame(), @encryptedBinary))

RETURN @decrypted

END
GO